package com.janwen.spring.ws.client;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

import javax.mail.Header;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

/**
 * @author janwen
 * Mar 8, 2013 1:06:55 PM
 * 
 */
public class HttpWebService {

	
	static final String message = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\"><theCityName>beijing</theCityName></getWeatherbyCityName></soap:Body></soap:Envelope>";
	public static void main(String[] args) throws ClientProtocolException, IOException {
		HttpClient httpClient = new DefaultHttpClient();
		HttpPost post = new HttpPost("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");
		//post.addHeader("SOAPAction", "http://WebXml.com.cn/getRegionCountry");
	//	post.addHeader("Content-Type","text/xml; charset=utf-8");
		//post.addHeader("Host","webservice.webxml.com.cn");
		StringEntity entity = new StringEntity(message,ContentType.TEXT_XML);
		post.setEntity(entity);
		HttpResponse response = httpClient.execute(post);
		String results = EntityUtils.toString(response.getEntity(), "UTF-8");
		System.out.println(results);
	}
}
